package com.truesai.entities.common;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import com.truesai.dto.KVItem;
/**
 * 代码组
 * @author XuLian
 *
 */
@Entity
@NamedQueries(
{
        @NamedQuery(name = CodeItem.ALL, query = "Select c from CodeItem c"),
        @NamedQuery(name = CodeItem.BY_TEXT, query = "Select c from CodeItem c where c.text = :text"),
        @NamedQuery(name = CodeItem.BY_ID, query = "Select c from CodeItem c where c.id = :id") })
@Table(name = "pub_code_item")
public class CodeItem extends KVItem {

	public static final String ALL = "CodeItem.all";

    public static final String BY_TEXT = "CodeItem.byText";

    public static final String BY_ID = "CodeItem.byId";
	
    @Column
    @NotNull
    @Size(min=2, max=10)
    private String groupId;
    
	@Override
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Long getId() {
		return super.getId();
	}

	@Override
	public void setId(Long id) {
		super.setId(id);
	}

	@Override
	@Column
	@NotNull
	@Size(min=2, max=20)
	public String getText() {
		return super.getText();
	}

	public CodeItem() {
		super();
	}
	
	public CodeItem(Long id, String text) {
		super(id, text);
	}
	
	public CodeItem(Long id, String text, String groupId) {
		super(id, text);
		this.groupId = groupId;
	}
	
	public CodeItem(String text, String groupId) {
		setText(text);
		this.groupId = groupId;
	}
	
	
	@Override
	public void setText(String text) {
		super.setText(text);
	}

	public String getGroupId() {
		return groupId;
	}

	public void setGroupId(String groupId) {
		this.groupId = groupId;
	}
	
	@Override
	public String toString() {
		return getText()!=null ? getText() : "";
	}
}
